<template>
  <div>
    <el-form ref="form" :model="form4" label-width="80px">
      <el-form-item label="入组前治疗记录">
        <el-radio-group v-model="form4.state" @change="stateHandle">
          <el-radio :label="1">有</el-radio>
          <el-radio :label="2">无</el-radio>
          <el-radio :label="3">不详</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-show="stateValue === 1" label="MG治疗:">
        <el-checkbox-group v-model="form4.mgTreatment" @change="handleChecked">
          <el-checkbox label="8" name="mgTreatment">溴吡斯的明</el-checkbox>
          <el-checkbox label="9" name="mgTreatment">醋酸泼尼松</el-checkbox>
          <el-checkbox label="5" name="mgTreatment">甲泼尼龙</el-checkbox>
          <el-checkbox label="7" name="mgTreatment">硫唑嘌呤</el-checkbox>
          <el-checkbox label="10" name="mgTreatment">他克莫司</el-checkbox>
          <el-checkbox label="2" name="mgTreatment">环孢素A</el-checkbox>
          <el-checkbox label="11" name="mgTreatment">吗替麦考酚酯</el-checkbox>
          <el-checkbox label="4" name="mgTreatment">甲氨蝶呤</el-checkbox>
          <el-checkbox label="3" name="mgTreatment">环磷酰胺</el-checkbox>
          <el-checkbox label="12" name="mgTreatment">注射用甲泼尼龙琥珀酸钠</el-checkbox>
          <el-checkbox label="6" name="mgTreatment">利妥昔单抗</el-checkbox>
          <el-checkbox label="13" name="mgTreatment">中药</el-checkbox>
          <el-checkbox label="1" name="mgTreatment">丙种球蛋白</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
    <ming v-show="stateValue === 1 && symptomIndex.indexOf('8') !== -1" ref="ming" />
    <pns v-show="stateValue === 1 && symptomIndex.indexOf('9') !== -1" ref="pns" />
    <jpn v-show="stateValue === 1 && symptomIndex.indexOf('5') !== -1" ref="jpn" />
    <lzpl v-show="stateValue === 1 && symptomIndex.indexOf('7') !== -1" ref="lzpl" />
    <tac v-show="stateValue === 1 && symptomIndex.indexOf('10') !== -1" ref="tac" />
    <hbsa v-show="stateValue === 1 && symptomIndex.indexOf('2') !== -1" ref="hbsa" />
    <xiaox v-show="stateValue === 1 && symptomIndex.indexOf('11') !== -1" ref="xiaox" />
    <jadl v-show="stateValue === 1 && symptomIndex.indexOf('4') !== -1" ref="jadl" />
    <hlxa v-show="stateValue === 1 && symptomIndex.indexOf('3') !== -1" ref="hlxa" />
    <zsyhpsn v-show="stateValue === 1 && symptomIndex.indexOf('12') !== -1" ref="zsyhpsn" />
    <ltx v-show="stateValue === 1 && symptomIndex.indexOf('6') !== -1" ref="ltx" />
    <zy v-show="stateValue === 1 && symptomIndex.indexOf('13') !== -1" ref="zy" />
    <bingqiu v-show="stateValue === 1 && symptomIndex.indexOf('1') !== -1" ref="bingqiu" />

    <el-button type="primary" @click="onSubmit">保存</el-button>
  </div>
</template>

<script>
import Ming from '../medicine/ming.vue'
import Pns from '../medicine/pns.vue'
import Jpn from '../medicine/jpn.vue'
import Lzpl from '../medicine/lzpl.vue'
import Tac from '../medicine/tac.vue'
import Hbsa from '../medicine/hbsa.vue'
import Xiaox from '../medicine/xiaox.vue'
import Jadl from '../medicine/jadl.vue'
import Hlxa from '../medicine/hlxa.vue'
import Zsyhpsn from '../medicine/zsyhpsn.vue'
import Ltx from '../medicine/ltx.vue'
import Zy from '../medicine/zy.vue'
import Bingqiu from '../medicine/bingqiu.vue'
import { addTreatmentBeforeEnrollment } from '@/api/testDashboard'
import { initData } from '@/api/data'

export default {
  components: { Ming, Pns, Jpn, Lzpl, Tac, Hbsa, Xiaox, Jadl, Hlxa, Zsyhpsn, Ltx, Zy, Bingqiu },
  data() {
    return {
      form4: {
        pid: this._routerRoot._route.query.id,
        state: 0,
        mgTreatment: []
      },
      query: {
        pid: this._routerRoot._route.query.id
      },
      symptomIndex: [],
      stateValue: 0,
      params: {
        id: '',
        pid: this._routerRoot._route.query.id,
        state: 0,
        mgTreatment: [],
        medicals: []
      }
    }
  },
  created() {
    initData('api/treatmentBeforeEnrollment/findByPid', this.query).then(data => {
      console.log(data)
      if (data) {
        this.params.id = data.id
        this.form4.state = data.state
        this.form4.mgTreatment = data.mgTreatment
        this.stateValue = data.state
        this.symptomIndex = data.mgTreatment
        data.medicals.forEach(element => {
          if (element.dId === 1) {
            this.$refs.bingqiu.form = element
          }
          if (element.dId === 2) {
            this.$refs.hbsa.form = element
          }
          if (element.dId === 3) {
            this.$refs.hlxa.form = element
          }
          if (element.dId === 4) {
            this.$refs.jadl.form = element
          }
          if (element.dId === 5) {
            this.$refs.jpn.form = element
          }
          if (element.dId === 6) {
            this.$refs.ltx.form = element
          }
          if (element.dId === 7) {
            this.$refs.lzpl.form = element
          }
          if (element.dId === 8) {
            this.$refs.ming.form = element
          }
          if (element.dId === 9) {
            this.$refs.pns.form = element
          }
          if (element.dId === 10) {
            this.$refs.tac.form = element
          }
          if (element.dId === 11) {
            this.$refs.xiaox.form = element
          }
          if (element.dId === 12) {
            this.$refs.zsyhpsn.form = element
          }
          if (element.dId === 13) {
            this.$refs.zy.form = element
          }
        })
      }
    })
  },
  inject: ['reload'],
  methods: {
    onSubmit() {
      this.params.state = this.form4.state
      this.params.mgTreatment = this.form4.mgTreatment
      this.params.medicals = []
      this.params.medicals.push(this.$refs.ming.form)
      this.params.medicals.push(this.$refs.pns.form)
      this.params.medicals.push(this.$refs.jpn.form)
      this.params.medicals.push(this.$refs.lzpl.form)
      this.params.medicals.push(this.$refs.tac.form)
      this.params.medicals.push(this.$refs.hbsa.form)
      this.params.medicals.push(this.$refs.xiaox.form)
      this.params.medicals.push(this.$refs.jadl.form)
      this.params.medicals.push(this.$refs.hlxa.form)
      this.params.medicals.push(this.$refs.zsyhpsn.form)
      this.params.medicals.push(this.$refs.zy.form)
      this.params.medicals.push(this.$refs.ltx.form)
      this.params.medicals.push(this.$refs.bingqiu.form)
      console.log(this.params)
      addTreatmentBeforeEnrollment(this.params).then(res => {
        alert('提交成功')
        this.reload()
        console.log(res)
      })
    },
    initData() {
      initData('api/treatmentBeforeEnrollment/findByPid', this.query).then(data => {
        console.log(data)
        if (data) {
          this.params.id = data.id
          this.form4.state = data.state
          this.form4.mgTreatment = data.mgTreatment
          this.stateValue = data.state
          this.symptomIndex = data.mgTreatment
          data.medicals.forEach(element => {
            if (element.dId === 1) {
              this.$refs.bingqiu.form = element
            }
            if (element.dId === 2) {
              this.$refs.hbsa.form = element
            }
            if (element.dId === 3) {
              this.$refs.hlxa.form = element
            }
            if (element.dId === 4) {
              this.$refs.jadl.form = element
            }
            if (element.dId === 5) {
              this.$refs.jpn.form = element
            }
            if (element.dId === 6) {
              this.$refs.ltx.form = element
            }
            if (element.dId === 7) {
              this.$refs.lzpl.form = element
            }
            if (element.dId === 8) {
              this.$refs.ming.form = element
            }
            if (element.dId === 9) {
              this.$refs.pns.form = element
            }
            if (element.dId === 10) {
              this.$refs.tac.form = element
            }
            if (element.dId === 11) {
              this.$refs.xiaox.form = element
            }
            if (element.dId === 12) {
              this.$refs.zsyhpsn.form = element
            }
            if (element.dId === 13) {
              this.$refs.zy.form = element
            }
          })
        }
      })
    },
    handleChecked(v) {
      this.symptomIndex = v
    },
    stateHandle(v) {
      this.stateValue = v
    }
  }
}
</script>

<style>

</style>
